/* name: build
 * author: 5ab
 * created at: 2024-06-04
 */
#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define ssz(x) (int((x).size()))

auto chmax = [](auto& x, auto y) { if (x < y) x = y; };
auto chmin = [](auto& x, auto y) { if (y < x) x = y; };

using ll = long long;
const int N = 300;

int f[N][N][N], a[N];

signed main()
{
	freopen("build.in", "r", stdin);
	freopen("build.out", "w", stdout);
	
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n;
	
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i], a[i]--;
	
	for (int i = 1; i <= n; i++)
		for (int j = i - 1; j < n; j++)
			for (int k = i - 1; k < n; k++)
				f[i][j][k] = min({
					f[i - 1][j][k] + (a[j - i + 1] != k - i + 1),
					f[i - 1][j - 1][k] + (a[j] != k - i + 1),
					f[i - 1][j][k - 1] + (a[j - i + 1] != k),
					f[i - 1][j - 1][k - 1] + (a[j] != k),
				});
	cout << f[n][n - 1][n - 1] << endl;
	
	return 0;
}
// started coding at: 06-04 10:22:58